using UnityEngine;
using System.Collections;

public class LittleBat : Ennemy
{
	public AudioClip[] ambientSound;
	
	protected bool m_Follow = false;
	
	protected bool mWaitForBack = false;
	
	protected override void PostSpawnProcess ()
	{
		if(Random.Range(0, 2) == 0)
			mWaitForBack = true;
		
		transform.position = new Vector3(transform.position.x,
		                                 mWalkableRect.Top,
		                                 transform.position.z);
		
		GetComponent<EnnemySound>().SetAmbient(ambientSound[Random.Range(0, ambientSound.Length)], 0.8f, 1.2f, 1.0f);
	}
	
	protected void Update()
	{
		if(!m_Follow)
		{
			if(!mWaitForBack || player.Instance.transform.position.x > transform.position.x)
				m_Follow = true;
		}
		else
		{
			transform.position = Vector3.MoveTowards(transform.position, player.Instance.transform.position, (LevelGenerator.sSpeed + 20.0f) * Time.deltaTime);
		}
	}
}
